#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
#define LOCAL_TEST 0
#define M 30


static void prime1(int pm[], int n){
	int gap, i, j, k, sqrt_n;
	pm[0]=2; pm[1]=3;
	for(i=5, j=2, gap=2; j<n; i+=gap, gap =6-gap){
		sqrt_n = (int)(floor(sqrt(i)+0.5));
		if(sqrt_n*sqrt_n>i) --sqrt_n;
		for(k=0; pm[k]<=sqrt_n && i%pm[k]; ++k);
		if(pm[k]>sqrt_n) pm[j++] = i;
	}
}

static void prime2(int pm[], int n){
	int i, j, k;
	pm[0] =2; pm[1]=3;
	for(i=5, j=2; j<n; i +=2){
		for(k=2; k<=i/2 && i%k; ++k);
		if(k>i/2) pm[j++] =i;
	}
}
static void solve(void){
	int x[M], y[M];
	int i, j, n;
	for(i=0; i<5; ++i){
		n = rand()%(M-10) + 1;
		prime1(x, n);
		prime2(y, n);
#if 1
		for(j=0; j<n; ++j) printf("%6d", x[j]);
		printf("\n");
		for(j=0; j<n; ++j) printf("%6d", y[j]);
		printf("\n");
#endif
		if(0==memcmp(x, y, n*sizeof(int))){
			printf("ok");
		}else{
			printf("fail");
		}
	}

}

#if LOCAL_TEST
void run(void){
		solve();
}
#endif
